<template>
  <view v-if="hasFree" >
    <uni-notice-bar show-icon scrollable color="#8e5632" :text="'您还有' + text1 + text2 + '的免费名额，请及时使用'" />
  </view>
</template>
<script>
	import { mapGetters } from 'vuex';
  import { getFreeInfoApi } from '@/http/api'
	export default {
		data() {
			return {
        hasFree: false,
        text1: '',
        text2: ''
			}
		},
		computed: {
			...mapGetters({
				userInfo: 'user/info',
				hasLogin: 'user/hasLogin'
			})
		},
    mounted() {
      this.refresh()
    },
		methods: {
      refresh() {
        let phone = this.userInfo.phonenumber;
        if (phone) {
          // 获取免费次数
          getFreeInfoApi({
            phone: this.userInfo.phonenumber
          }).then(res => {
            if (res.code === 200) {
              if (res.data.nameAnalysis !== 0 || res.data.wedlock !== 0) {
                this.hasFree = true;
                if (res.data.nameAnalysis !== 0 ) this.text1 = ` ${res.data.nameAnalysis}次 姓名测算`;
                if (res.data.wedlock !== 0 ) this.text2 = `${this.text != '' ? '，' : ''}${res.data.wedlock}次 婚姻测算`;
              }else{
                this.hasFree = false;
              }
            }
          })          
        }
      }
		}
	}
</script>

<style>
</style>